package org.erp.product.infrastructure.mq.service;

import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.constant.RabbitmqConstant;
import org.erp.common.enums.DeviceInventoryEvent;
import org.erp.product.domain.dto.AsyncMessageStatusDto;
import org.erp.product.domain.dto.DickerDto;
import org.erp.product.domain.dto.TransferDto;
import org.erp.product.domain.entity.ConnectLog;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author libin
 * @version 1.0
 * @description:
 * @date 2025/11/25 21:10
 **/
@Log4j2
@Service
@AllArgsConstructor
public class ProductRabbitService {

    private final RabbitTemplate rabbitTemplate;


    /**
     * 发送异步调拨消息
     *
     * @param transferDto
     * @param dickerDtoList
     */
    public void sendTransferMessage(TransferDto transferDto, List<DickerDto> dickerDtoList) {
        AsyncMessageStatusDto asyncMessageStatusDto = AsyncMessageStatusDto.buildTransferAsyncMessageStatusDto(transferDto, dickerDtoList);
        rabbitTemplate.convertAndSend(RabbitmqConstant.ERP_STORE_EXCHANGE, RabbitmqConstant.ERP_STORE_ROUTING_KEY
                , JSONObject.toJSONString(asyncMessageStatusDto));
    }

    public void sendActionMessage(List<ConnectLog> warehouseList, DeviceInventoryEvent deviceInventoryEvent) {
        AsyncMessageStatusDto asyncMessageStatusDto = AsyncMessageStatusDto.buildActionAsyncMessageStatusDto(warehouseList, deviceInventoryEvent);
        rabbitTemplate.convertAndSend(RabbitmqConstant.ERP_STORE_EXCHANGE, RabbitmqConstant.ERP_STORE_ROUTING_KEY
                , JSONObject.toJSONString(asyncMessageStatusDto));
    }
}
